package jianzhioffer;

/**
 * 跳台阶
 * 一次只能 跳一个 or 跳两个，求跳到target一共有多少跳法
 * Created by yzy on 2019-12-26 17:43
 */
public class JumpFloor {

    public static void main(String[] args) {
        int target=10;
    }

    /**
     * p[target] = p[target-1] + p[target-2]
     * 也就是斐波那契数列，但是不要用递归，用动态规划的思路，保存前一个计算的结果，从下往上算
     * @param target
     * @return
     */
    public static int jumpFloor(int target){
        if(target <= 2){
            return target;
        }
        int pre=1;
        int curr=2;
        int floor=3;
        int tmp;
        while(target >= floor){
            floor++;
            tmp = curr;
            curr = curr + pre;
            pre = tmp;
        }

        return curr;
    }
}
